import {createStore} from 'vuex'
import {tabItem} from '@/store'

interface State {
    tabList:Array<tabItem>,
    isCollapse: boolean,
    currentRouteName: string
}
export default createStore<State>({
    state(){
        return {
            tabList: [
                {
                    path: '/resume',
                    name: '个人简历'
                }
            ],
            isCollapse: false,
            currentRouteName: ''
        }
    },
    mutations:{
        changeCollapse(state:State){
            state.isCollapse = !state.isCollapse
        },
        addTab(state:State, tabItem:tabItem){           
            const isSome = state.tabList.some(item=> item.path === tabItem.path)
            if(!isSome){
                console.log('tabItem', tabItem)
                state.tabList.push(tabItem)
            }
        },
        removeTab(state:State, tabName: string){
            const index = state.tabList.findIndex(item=> item.path === tabName)
            if(index !== -1){
                state.tabList.splice(index, 1)
            }
        },
        setCurrentRouteName(state:State, currentName: string){
            state.currentRouteName = currentName
        },
        //关闭所有标签（除）
        // closeAllTabs(state:State){

        // },
        // closeOtherTabs(state:State, tabName:string, type:string){

        // }
        
    },     
    actions: {
        changeCollapse(content:any){            
            content.commit('changeCollapse')
        }
    },
    getters:{
        getTab(state:State){
            return state.tabList
        }
    }
})